package top.rainbowecho.ai.config;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Ai 微服务相关配置
 *
 * @author rainbow
 * @since 2019/11/23 12:54
 */
@Configuration
public class AiServiceConfig {
    private RobotConfiguration robotConfiguration;

    @Autowired
    public void setRobotConfiguration(RobotConfiguration robotConfiguration) {
        this.robotConfiguration = robotConfiguration;
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }

    @Bean
    public AipContentCensor aipContentCensor() {
        BaiduCloudConfiguration baiduPlatform = robotConfiguration.getBaidu();
        AipContentCensor client = new AipContentCensor(baiduPlatform.getAppId(), baiduPlatform.getApiKey(), baiduPlatform.getSecretKey());
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        return client;
    }
}
